package com.egene.tw.activity.contact;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.egene.tw.R;
import com.egene.tw.base.RecycleBaseAdapter;
import com.egene.tw.model.LeaveMsg;
import com.egene.tw.model.ReplyMsg;

import java.util.List;

/**
 * Created by WZX on 2015/8/16.
 */
public class LeaveMessageAdapter extends RecycleBaseAdapter {
    public LeaveMessageAdapter() {
    }

    public LeaveMessageAdapter(View headerView) {
        mHeaderView = headerView;
    }

    @Override
    public View onCreateItemView(ViewGroup parent, int viewType) {
        return getLayoutInflater(parent.getContext()).inflate(R.layout.item_msg, null);
    }

    @Override
    protected RecycleBaseAdapter.ViewHolder onCreateItemViewHolder(View view, int viewType) {
        return new ViewHolder(viewType, view);
    }

    @Override
    protected void onBindItemViewHolder(RecycleBaseAdapter.ViewHolder vh, int position) {
        super.onBindItemViewHolder(vh, position);
        LeaveMessageAdapter.ViewHolder holder = (LeaveMessageAdapter.ViewHolder) vh;
        LeaveMsg item = (LeaveMsg) _data.get(position);
        holder.tvName.setText(item.getUserName());
        holder.tvContent.setText(item.getMessage());
        holder.tvData.setText(item.getCreateDatetimeString());
        holder.llReply.removeAllViews();

        List<ReplyMsg> replyList = item.getReplyMsg();
        if(replyList != null){
            for(ReplyMsg msg : replyList){
                View view = mInflater.inflate(R.layout.item_msg, null);
                ViewHolder msgHolder = new ViewHolder(0,view);
                msgHolder.tvName.setText(msg.getReplyUserName());
                msgHolder.tvContent.setText(msg.getReplyInfo());
                msgHolder.tvData.setText(msg.getReplyDatetimeString());
                holder.llReply.addView(view);
            }
        }

//        holder.tvContent.setText(item.getContent());

    }

    public static class ViewHolder extends RecycleBaseAdapter.ViewHolder {
        public TextView tvName;
        public TextView tvData;
        public TextView tvContent;
        public LinearLayout llReply;
//
        public ViewHolder(int viewType, View view) {
            super(viewType, view);
            tvName = (TextView) view.findViewById(R.id.tvName);
            tvData = (TextView) view.findViewById(R.id.tvData);
            tvContent = (TextView) view.findViewById(R.id.tvContent);
            llReply = (LinearLayout) view.findViewById(R.id.llReply);
        }
    }
}
